package com.example.replacebooks.mapper;

import com.example.replacebooks.entity.Params;
import com.example.replacebooks.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface UserMapper extends Mapper<User> {
    List<User> findBySearch(@Param("params") Params params);

    @Select("select * from user where userid = #{userid} limit 1")
    User findByUserid(@Param("userid") Integer userid);

    @Select("select * from user where username = #{username} limit 1")
    User findByUsername(@Param("username") String username);

    @Update("update user set name = #{name},userimg=#{userimg},sex = #{sex},age = #{age},signature = #{signature},birthday = #{birthday} where userid = #{userid}")
    void updateByuserid(User user);

    @Select("select * from user where username = #{username} and password = #{password} and role = #{role} limit 1")
    User findUseridAndPasswordAndRole(@Param("username") String username,@Param("password") String password,@Param("role") Integer role);
}

